import Vue from 'vue'
import './plugins/axios'
import router from './router'
import axios from 'axios'
import vueAxios from 'axios';
import store from './store'

import App from './App.vue';
//封装的evn模块化配置文件
// import env from './env'

//mock开关
// const mock=false
// if (mock) {
//     require('./mock/api');
// }
//请求url 可以根据前端的跨域方式调整 /a/b:/api/a/b=>/a/b
axios.defaults.baseURL = '/api';
// axios.defaults.baseURL = 'https://www.easy-mock.com/mock/5ef8c0bdd932361141717b03/mishop';
//根据环境变量获取不同的请求地址
// axios.defaults.baseURL = env.baseURL;
//请求超时时间 8s
axios.defaults.timeout =8000;
//接口错误拦截
axios.interceptors.response.use(function (response) {
    let res = response.data;
    if (res.status == 0) {//请求
        // console.log('data'+res)
        return res.data
    }else if(res.status == 10){//未登录
        window.location.href = '/#/login';
    }else {
        alert(res.msg);
    }
});

//挂载axios
Vue.use(vueAxios, axios);

Vue.config.productionTip = false;//正式环境需要设置false

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
